package dyyx.util;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

/**
 * 
 * @author dugang 时间打点统计数据对象
 *
 */
public class TimeInfo  {
	/**
	 * 时间等于0的个数
	 */
	public final AtomicLong zeroCount = new AtomicLong(0);
	public final AtomicLong sum = new AtomicLong(0);
	public final AtomicLong count = new AtomicLong(0);
	//public long avg;
	public long max;
	
	
	// count great than 100ms
    public final AtomicLong countGt100 = new AtomicLong(0);
    public final AtomicLong countGt200 = new AtomicLong(0);
    public final AtomicLong countGt500 = new AtomicLong(0);
    public final AtomicLong countGt1000 = new AtomicLong(0);

	/**
	 * 当前时间
	 */
	public long current;
	
	/**
	 * 最大耗时对应的时间点
	 */
	public long maxTime;
	
	
	  public long getAvg(){
	    	long counttmp = this.count.get();
			long sumtmp = this.sum.get();
			if(counttmp<=0){
				return 0;
			}
			return sumtmp / counttmp;
	    }

	@Override
    public String toString(){
		Map map = new HashMap();
		map.put("zeroCount", zeroCount.longValue());
		map.put("count", count.longValue());
		map.put("avg", getAvg());
    	return map.toString();
    }
   
}
